package com.oj.friend.controller.exam;

import com.oj.common.core.constants.HttpConstants;
import com.oj.common.core.controller.BaseController;
import com.oj.common.core.domain.R;
import com.oj.common.core.domain.TableDataInfo;
import com.oj.friend.domain.exam.dto.ExamQueryDTO;
import com.oj.friend.domain.question.vo.QuestionDetailVO;
import com.oj.friend.service.impl.ExamServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author bin
 * @Date 2025/5/28
 */
@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    private ExamServiceImpl examService;

    @GetMapping("/semiLogin/list")
    @Operation(summary = "竞赛列表", description = "根据查询条件筛选查询竞赛列表")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        //这个分页的list使用写xml的方式进行查询 不在像QuestionServiceImpl那样使用mybatisPlus进行查询
        return examService.list(examQueryDTO);
    }


    @GetMapping("/semiLogin/redis/list")
    @Operation(summary = "竞赛列表", description = "根据查询条件筛选查询竞赛列表")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO) {
        // TODO 遗留问题 进行中的竞赛变成历史竞赛后 redis中 e:t:l 和 e:h:l 的更新
        // 已经通过xxlJob解决
        return examService.redisList(examQueryDTO);
    }

    @GetMapping("/getFirstQuestion")
    @Operation(summary = "获取竞赛的第一个题目", description = "根据examId获取竞赛的第一个题目")
    public R<String> getFirstQuestion(Long examId) {
        System.out.println("getFirstQuestion-----" + examId);
        return R.ok(examService.getFirstQuestion(examId));
    }

    @GetMapping("/nextQuestion")
    @Operation(summary = "获取竞赛下一个题目", description = "根据examId获取竞赛的下一题目")
    public R<String> getNextQuestion(Long examId, Long questionId) {
        System.out.println("getNextQuestion-----" + examId + questionId);
        return R.ok(examService.getNextQuestion(examId, questionId));
    }

    @GetMapping("/preQuestion")
    @Operation(summary = "获取竞赛下一个题目", description = "根据examId获取竞赛的下一题目")
    public R<String> getPreQuestion(Long examId, Long questionId) {
        System.out.println("getPreQuestion-----" + examId + questionId);
        return R.ok(examService.getPreQuestion(examId, questionId));
    }

}
